<%@ taglib prefix="c" uri="jakarta.tags.core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <base href="<%=request.getContextPath()%>/">
    <meta charset="UTF-8">
    <title>病单报告详情 - 医疗预约系统</title>
    <style>
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
            background-color: #f5f5f5;
            margin: 0;
            padding: 0;
            line-height: 1.6;
        }
        .container {
            max-width: 900px;
            margin: 20px auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
        }
        h1 {
            color: #333;
            margin-bottom: 25px;
            padding-bottom: 10px;
            border-bottom: 2px solid #eaeaea;
        }
        .detail-item {
            margin-bottom: 15px;
            padding: 10px 0;
            border-bottom: 1px solid #f0f0f0;
        }
        .detail-label {
            font-weight: bold;
            display: inline-block;
            width: 120px;
            color: #666;
        }
        .btn {
            padding: 8px 16px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            margin-right: 10px;
            margin-top: 20px;
            transition: background-color 0.3s;
        }
        .btn-primary {
            background-color: #007bff;
            color: white;
        }
        .btn-primary:hover {
            background-color: #0056b3;
        }
        .btn-secondary {
            background-color: #6c757d;
            color: white;
        }
        .btn-secondary:hover {
            background-color: #5a6268;
        }
        .btn-danger {
            background-color: #dc3545;
            color: white;
        }
        .btn-danger:hover {
            background-color: #c82333;
        }
        .error-message {
            color: #dc3545;
            margin-top: 10px;
            padding: 10px;
            background-color: #f8d7da;
            border-radius: 4px;
        }
        .form-control {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-size: 14px;
            box-sizing: border-box;
        }
        textarea.form-control {
            height: 120px;
            resize: vertical;
            font-family: inherit;
        }
        .report-content {
            margin-top: 20px;
            background-color: #f9f9f9;
            padding: 15px;
            border-radius: 4px;
            border-left: 4px solid #007bff;
        }
    </style>
</head>
<body>
<div class="container">
        <h1>病单报告详情</h1>
            
            <div class="report-content">
                <form id="updateReportForm" action="report/update" method="post">
                    <input type="hidden" name="reportid" value="${report.reportid}">
                    
                    <div class="detail-item">
                        <span class="detail-label">病单号：</span>
                        <span>${report.reportid}</span>
                    </div>
                    
                    <div class="detail-item">
                        <span class="detail-label">用户姓名：</span>
                        <span>${report.user.username}</span>
                        <input type="hidden" name="userid" value="${report.userid}">
                    </div>
                    
                    <div class="detail-item">
                        <span class="detail-label">科室：</span>
                        <span>${report.appointment.visit.department.deptname}</span>
                        <input type="hidden" name="appointmentid" value="${report.appointmentid}">
                    </div>
                    
                    <div class="detail-item">
                        <span class="detail-label">症状：</span>
                        <!-- 非病人用户可以编辑，病人用户只读 -->
                        <c:choose>
                            <c:when test="${loginAdmin != null && loginAdmin.type == 1}">
                                <textarea name="symptoms" class="form-control" readonly>${report.symptoms}</textarea>
                            </c:when>
                            <c:otherwise>
                                <textarea name="symptoms" class="form-control">${report.symptoms}</textarea>
                            </c:otherwise>
                        </c:choose>
                    </div>
                    
                    <div class="detail-item">
                        <span class="detail-label">医生建议：</span>
                        <!-- 非病人用户可以编辑，病人用户只读 -->
                        <c:choose>
                            <c:when test="${loginAdmin != null && loginAdmin.type == 1}">
                                <textarea name="doctoradvice" class="form-control" readonly>${report.doctoradvice}</textarea>
                            </c:when>
                            <c:otherwise>
                                <textarea name="doctoradvice" class="form-control">${report.doctoradvice}</textarea>
                            </c:otherwise>
                        </c:choose>
                    </div>
                    
                    <div class="detail-item">
                        <span class="detail-label">生成时间：</span>
                        <span>${report.createtime}</span>
                    </div>
                    
                    <!-- 只有非病人用户可以看到保存修改和删除按钮 -->
                    <c:if test="${loginAdmin == null || loginAdmin.type != 1}">
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-save"></i> 保存修改
                        </button>
                        <a href="javascript:void(0)" class="btn btn-danger" onclick="deleteReport(${report.reportid})">
                            <i class="fas fa-trash-alt"></i> 删除报告
                        </a>
                    </c:if>
                    <a href="report/find" class="btn btn-secondary">
                        <i class="fas fa-arrow-left"></i> 返回列表
                    </a>
                    
                    <c:if test="${not empty error}">
                        <div class="error-message">${error}</div>
                    </c:if>
                </form>
            </div>

<script>
    function deleteReport(reportId) {
        if (confirm('确定要删除这个病单报告吗？')) {
            window.location.href = 'report/delete?reportId=' + reportId;
        }
    }
</script>
</body>
</html>